package org.footballmanager.pandafootball.common.util;

import lombok.extern.slf4j.Slf4j;
import org.footballmanager.pandafootball.system.domain.FootReward;
import org.footballmanager.pandafootball.system.domain.FootYqts;
import org.footballmanager.pandafootball.system.service.impl.RedisService;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

@Slf4j
public class RandomNumber {
    private RandomNumber() {
    }

    public static String getRandomNumber() {
        Random rand = new Random();
        int num = rand.nextInt(100);
        String result;
        if(num > 90){
            result = processChip(rand, 20, "顶级球星");
        }else if(num > 85){
            result = processChip(rand, 10, "超级球星");
        }else if(num > 80){
            result = processChip(rand, 8, "洲际球星");
        }else if(num > 75){
            result = processChip(rand, 6, "普通球星");
        }else{
            result = processChip(rand, 4, "大众/白人");
        }
        return result;
    }

    private static String processChip(Random rand, Integer bound, String chipName) {
        int rnum = rand.nextInt(bound);
        return rnum == 0 ? chipName : chipName + "碎片";
    }

    public static int randomNumber() {
        Random r = new Random();
        return r.nextInt(100) + 1;
    }

    public static String randomStrByNum(Integer num) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < num; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    public static String randomGetPerson(FootReward reward){
        Random r = new Random();
        //55+30+10+5+0
        int result = r.nextInt(reward.getWhite() + reward.getGreen() + reward.getBlue() + reward.getPurple() + reward.getOrange());
        String qydj = "大众/白人";
        if(result <= reward.getWhite()){
            qydj = "大众/白人";
        }else if(result <= reward.getGreen() + reward.getWhite()) {
            qydj = "普通球星";
        }else if(result <= reward.getBlue() + reward.getGreen() + reward.getWhite()){
            qydj = "洲际球星";
        }else if(result <= reward.getPurple() + reward.getBlue() + reward.getGreen() + reward.getWhite()){
            qydj = "超级球星";
        }else if(result <= reward.getOrange() + reward.getPurple() + reward.getBlue() + reward.getGreen() + reward.getWhite()){
            qydj = "顶级球星";
        }
        return qydj;
    }

    public static String randomContent(RedisService redisService) {
        List<FootYqts> list = (List<FootYqts>) redisService.get("listyqts");
        if (list != null && !list.isEmpty()) {
            Random r = new Random();
            FootYqts yq = list.get(r.nextInt(list.size() - 1));
            if (null != yq && !StringUtils.isEmpty(yq.getContent())) {
                return yq.getContent();
            }
        }
        return "熊猫足球分为常规赛和季后赛哦";
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        for (Integer i = 0; i < 9; i++) {
            list.add(i.toString());
        }
        for (int i = 0; i < 10; i++) {
            log.info(RandomNumber.getRandomNumber() + ",");
        }
    }
}
